<template>
  <div id="root">
    <h1>人员列表</h1>
        <h2 style="color: red;">HelloWorld 组件的求和为{{ sum }}</h2>
        <input type="text" placeholder="输入人员姓名" v-model="name"/> 
        <button @click="addPareson">添加</button>
        <ul>
            <li v-for="preson in presonList" :key="preson.id"> {{preson.name}}</li>
        </ul>
  </div>
</template>

<script>

import { mapState } from 'vuex'

export default {
    data(){
        return {
            name:""
        }
    },
    computed:{
        ...mapState(['presonList','sum']),
    },
    methods:{
        addPareson(){
            this.$store.commit('ADD_PRESON',this.name)
            this.name = ""
        }
    }
}
</script>

<style>

</style>